#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int INF = 1 << 30;
const ldb pi = fabsl(atan2(0.0, -1.0));
using namespace std;

int n;
int a[1000010], b[1000010], op[1000010];

void Load()
{
	cin >> n;
	int i;
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		op[a[i]] = i;
	}
	int j;
	for (j = 1; j <= n; j++)
	{
		scanf("%d", &b[j]);
		b[j] = op[b[j]];
	}

}

int d[1000010];

void Solve()
{
	int i;
	int l, r, mid, sz, res;
	sz = 0;
	d[0] = INF;
	for (i = 1; i <= n; i++)
	{
		//d[1] = max(d[1], a[i]);
		l = 0;
		r = sz;
		while (l <= r)
		{
			mid = (l + r) / 2;
			if (d[mid] > b[i])
			{
				res = mid;
				l = mid + 1;
			}
			else r = mid - 1;
		}
		d[res + 1] = max(d[res + 1], b[i]);
		sz = max(sz, res + 1);
	}
	cout << sz;

}

#define file "d"
int main()
{
	#ifndef ONLINE_JUDGE
	freopen(file".in", "rt", stdin);
	freopen(file".out", "wt", stdout);
	#endif
	Load();
	Solve();
	return 0;
}